#pragma once
#include "Ray.h"
class BBox{
public:
	BBox(float _xmin, float _ymin, float _zmin, float _xmax, float _ymax, float _zmax);	//for individual shapes
	BBox(vec3 min, vec3 max);	//opposite corners of the box
	BBox();						//for groups where you don't know the size yet
	BBox(BBox _a, BBox _b);		//for combining two BBoxes
	~BBox();	

	float xmin(){ return thexmin; }
	void xmin(float _x){ thexmin = _x; }
	float ymin(){ return theymin; }
	void ymin(float _y){ theymin = _y; }
	float zmin(){ return thezmin; }
	void zmin(float _z){ thezmin = _z; }
	float xmax(){ return thexmax; }
	void xmax(float _x){ thexmax = _x; }
	float ymax(){ return theymax; }
	void ymax(float _y){ theymax = _y; }
	float zmax(){ return thezmax; }
	void zmax(float _z){ thezmax = _z; }

	vec3 minBound(){ return theMinBound; }
	vec3 maxBound(){ return theMaxBound; }
	//return a vec3 containing the bounding box's dimensions
	vec3 dimensions(){ return theMaxBound - theMinBound; }

	void addBBox(BBox _b);		//add a BBox to the bounds
	void addBBox(vec3 _min, vec3 _max);
	void addPoint(vec3 _pt);	//add a point to the bounds

	bool intersect(Ray *_theRay, float &_t0, float &_t1);

private:
	float thexmin, thexmax, theymin, theymax, thezmin, thezmax;
	vec3 theMinBound, theMaxBound;
	static vec3 maxVec(vec3 _a, vec3 _b){ return vec3(max(_a.x, _b.x), max(_a.y, _b.y), max(_a.z, _b.z)); }
	static vec3 minVec(vec3 _a, vec3 _b){ return vec3(min(_a.x, _b.x), min(_a.y, _b.y), min(_a.z, _b.z)); }

};

